from typing import List


class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        dp0, dp1 = 0, -prices[0]
        for i in range(len(prices)):
            dp0 = max(dp0, dp1 + prices[i])
            dp1 = max(dp1, dp0 - prices[i])
        return dp0

    def maxProfit2(self, prices: List[int]) -> int:
        ans = 0
        for i in range(1, len(prices)):
            ans += max(0, prices[i] - prices[i - 1])
        return ans
